import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'

/**
 * 路由配置
 * 定义应用的页面路由
 */
const routes: RouteRecordRaw[] = [
  {
    path: '/',
    name: 'home',
    component: () => import('@/views/Home.vue'),
    meta: {
      title: '首页',
      keepAlive: true
    }
  },
  {
    path: '/about',
    name: 'about',
    component: () => import('../views/About.vue'),
    meta: {
      title: '关于',
      keepAlive: false
    }
  },
  {
    path: '/draw',
    name: 'draw',
    component: () => import('../views/draw.vue'),
    meta: {
      title: '绘图',
      keepAlive: false
    }
  },
  // 404页面
  {
    path: '/:pathMatch(.*)*',
    name: 'notFound',
    component: () => import('../views/NotFound.vue')
  }
]

/**
 * 创建路由实例
 */
const router = createRouter({
  history: createWebHistory(),
  routes
})

/**
 * 全局前置守卫
 * 可用于权限验证、修改页面标题等
 */
// router.beforeEach((to, from, next) => {
//   // 设置页面标题
//   document.title = to.meta.title as string || '项目名称'
//   next()
// })

export default router